package LeetCode;

public class No35 {
    public static void main(String[] args) {
        int[] a = new int[]{1};
        System.out.println(searchInsert(a, 0));
    }


    public static int searchInsert(int[] nums,int target){
        int left=0,right=nums.length-1;
        while(left<=right){
            int i = (left+right)/2;
            if(nums[i]<target) left=i+1;
            if(nums[i]>target) right=i-1;
            if(nums[i]==target) return i;
        }
        return left;
    }

//    public static int searchInsert(int[] nums, int target) {
//        for (int i = 0,j=nums.length-1; i <= j; i++,j--) {
//            if(nums[i]>target) return i;
//            if(nums[j]<target) return j+1;
//            if(nums[i]==target) return i;
//            if(nums[j]==target) return j;
//        }
//        return 0;
//    }
}
